package solutions.leetcode.easy;

import solutions.lib.BaseSolution;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/day-of-the-year/">1154.一年中的第几天</a>
 */
public class Solution1154 extends BaseSolution {

    public int dayOfYear(String date) {
        String[] parts = date.split("-");
        int year = Integer.parseInt(parts[0]);
        int month = Integer.parseInt(parts[1]) - 1;
        int day = Integer.parseInt(parts[2]);
        int[] sum = {
                31,
                year % 400 == 0 || (year % 100 != 0 && year % 4 == 0) ? 29 : 28,
                31,
                30,31,30,
                31,31,30,
                31,30,31
        };
        int count = 0;
        for (int i = 0; i < month; i++) {
            count += sum[i];
        }
        return count + day;
    }

    public static void main(String[] args) {
        Solution1154 solution = new Solution1154();
        System.out.println(solution.dayOfYear("2003-03-01"));
    }
}